package org.darkforest.common.services.impl;

import org.darkforest.common.services.PXianShiService;
import org.darkforest.dao.mapper.PXianshiGoodsMapper;
import org.darkforest.dao.mapper.PXianshiMapper;
import org.darkforest.model.PXianshi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Libing on 2015/6/19.
 */
@Service
@Transactional
public class PXianShiServiceImpl implements PXianShiService {

    @Autowired
    private PXianshiMapper pXianshiMapper;

    @Autowired
    private PXianshiGoodsMapper pXianshiGoodsMapper;

    @Override
    public PXianshi findTimeLimitedBuyingActiveByPage(PXianshi pXianshi) {
        pXianshi.setResultList(pXianshiMapper.findTimeLimitedBuyingActive(pXianshi));
        return pXianshi;
    }

    @Override
    public boolean deleteXianshiActiveByKey(Integer activeId) {
        try{
            pXianshiMapper.deleteByPrimaryKey(activeId);
            pXianshiGoodsMapper.deleteByXianshiId(activeId);
            return true;
        }catch(Exception e){
            return false;
        }

    }


    public void addPxianshiActive(PXianshi pXianshi) {
        pXianshiMapper.insertSelective(pXianshi);
    }


    public PXianshi getPXianshiActiveByKey(Integer xianshiId) {
        return pXianshiMapper.selectByPrimaryKey(xianshiId);
    }

    /**
     * 根据条件查询特卖活动
     *
     * @param pxianshi
     * @return
     */
    @Override
    public List<PXianshi> findPXianShiByCondition(PXianshi pxianshi) {
        return this.pXianshiMapper.findPXianShiByCondition(pxianshi);
    }

    @Override
    public void updatePXianShiStateBatch(Map<String, Object> pxianshi) {
        this.pXianshiMapper.updatePXianShiStateBatch(pxianshi);
    }


}
